home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / dtr / dtr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  55.1 KB  |  2,186 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/DTR/RCS/dtr.c,v 1.12 92/05/29 12:42:01 drapeau Exp $ */
  25. /* $Log:    dtr.c,v $
  26.  * Revision 1.12  92/05/29  12:42:01  drapeau
  27.  * Modified code to track new name of the MAEstro "Selection" structure;
  28.  * it is now named "MAESelection".
  29.  * 
  30.  * Revision 1.11  92/03/02  12:27:17  drapeau
  31.  * Modified calls to SetCurrentSelection() to pass an extra parameter:
  32.  * a pointer to a MAEstro Selection structure.  This was done to
  33.  * accommodate calls to SetCurrentSelection from the Receiver
  34.  * method SetSelection().  Before these changes, SetSelection() (and
  35.  * SetCurrentSelection()) did not handle requests for partial selections.
  36.  * 
  37.  * Revision 1.10  92/01/09  12:41:10  drapeau
  38.  * Slight modifications to the code to make it ANSI-compliant.
  39.  * 
  40.  * Revision 1.0  92/01/07  15:07:42  drapeau
  41.  * *Modified main(), so that in now sets default locations for the DTR
  42.  *  main and edit list panels.
  43.  * *Modified QuitDtr() so that it now checks for unsaved audio files
  44.  *  and unsaved edit lists.
  45.  * * Removed EditingHandler() since it is no longer needed.  The text
  46.  *  field that used to show the name of the current document has been
  47.  *  removed.
  48.  * *Removed EditModeSettingNotifyHandler(), since the Edit Mode choice
  49.  *  has been replaced with a menu item.
  50.  * *Removed EditListPopUpDoneButtonHandler() since it is no longer needed.
  51.  * *Removed NewEditListTextFieldHandler() since it is no longer needed.
  52.  * Also, Made a number of cosmetic changes to make code easier to read and
  53.  * to conform to programming specifications.
  54.  * 
  55.  * Revision 0.34  91/10/09  17:21:42  derek
  56.  * Save Edit List bug fixed.
  57.  * 
  58.  * Revision 0.33  91/09/30  16:13:07  derek
  59.  * DTR will now disconnect from the Port Manager when it quits.  Also,
  60.  * a number of printf statements are removed.
  61.  * 
  62.  * Revision 0.32  91/09/24  16:49:43  derek
  63.  * Zoom level's max value is changed from 50 to 4.
  64.  * 
  65.  * Revision 0.31  91/09/18  22:47:18  derek
  66.  * The following things are done:
  67.  * 1.    The Makefile is changed corresponding to the changes in collab/.
  68.  * 2.    Copyright messages included.
  69.  * 3.    Some minor bugs fixed.
  70.  * 
  71.  * Revision 0.30  91/08/28  13:02:59  derek
  72.  * The following changes are made:
  73.  * 1.    I ahve written an if-statement checking if NewSender() returns
  74.  *     NULL.  If so, DTR will notice_prompt the user that the
  75.  *     PortManager is absent.
  76.  * 2.    "Illegal Zoom value" bug in ZoomLevelTextField is fixed.
  77.  * 
  78.  * Revision 0.29  91/08/27  18:06:01  derek
  79.  * The SizeToFit bug is fixed.
  80.  * 
  81.  * Revision 0.28  91/08/27  17:22:40  derek
  82.  * The zooming bug is fixed in this version.
  83.  * 
  84.  * Revision 0.27  91/08/21  17:47:00  derek
  85.  * The big canvas "mis-placed" bug is fixed.
  86.  * 
  87.  * Revision 0.26  91/08/21  11:34:11  derek
  88.  * The following changes are made:
  89.  * 1.    Now the duration and size of the recorded sound will be displayed
  90.  *     during recording.
  91.  * 2.    I have changed GetSelection() corresponding to the request of Tek joo
  92.  * 3.    Info Panel is added to the application.
  93.  * 4.    Fixed SizeToFitHandler() so that when no file or buffer is currently
  94.  *     loaded, it would not do anything (except giving a warning
  95.  *     notice_prompt).
  96.  * 5.    Inplemented the `Close' Menu option in the document menu.
  97.  * 6.    Fixed the bug in which after ClearAll and I press PreviewEdit,
  98.  *     the edit wont be played.
  99.  * 7.    I have made the changes corresponding to the change in OpenPanel's
  100.  *     name.  (from OpenPanel to Browse).
  101.  * 8.    Incorporated BrowseCheck to check command line arg.
  102.  * 9.    Changed most EditingStatusMessages to NoticePrompts.
  103.  * 10.    SoundFileSaveAsPopUp and EditListSaveAsPopUp are removed 
  104.  *     from the application.
  105.  * 
  106.  * Revision 0.25  91/08/16  18:10:31  derek
  107.  * 
  108.  * The following things are done:
  109.  * 1.    I have fixed an openpanel bug in my code in which I 
  110.  *     made the app return the wrong values to OpenHandler and
  111.  *     the SaveHandler.
  112.  * 2.    The flashing color of the play button has been changed from
  113.  *     Red to Green.
  114.  * 3.    Fixed a quantization bug: Buffer.play.end, when converted
  115.  *     from endingTimeInSec, should not exceed Buffer_hdr_data_size - 1.
  116.  * 
  117.  * Revision 0.24  91/08/14  18:16:42  derek
  118.  * The following things are done:
  119.  * 1.    I changed the name of the "save as" and "save" menu options
  120.  *     to be more specific.  ie. to "save sound file" and "save edit list".
  121.  * 2.    I removed the preview panel popup and replaced it with a preview
  122.  *     edit button.
  123.  * 3.    I changed the message displayed by UpdateSpaceOnTmp() to consist
  124.  *     only of the time remaining and the amount of space left.  There is
  125.  *     no more percentage indicating the capacity of /usr/tmp.
  126.  * 
  127.  * Revision 0.23  91/08/14  16:13:59  derek
  128.  * Fixed a few saving/appending bugs.
  129.  * 
  130.  * Revision 0.22  91/08/13  20:38:23  derek
  131.  * The buttons (play, pause, record) will now flash after they are pressed.
  132.  * This only applies to times when audio files (not edit-lists) are 
  133.  * played.
  134.  * 
  135.  * Revision 0.21  91/08/08  21:44:31  derek
  136.  * Fixed a number of bugs.
  137.  * 
  138.  * Revision 0.20  91/08/08  11:02:04  derek
  139.  * This is a cleaner version.  I have removed lots of printf/fprintf 
  140.  * statements from it, and have also cleaned up the code using xsaber.
  141.  * This version should run substantially faster.
  142.  * 
  143.  * Revision 0.19  91/08/07  16:24:04  derek
  144.  * The Edit list part of DTR is done.  OpenPanel is also incorporated.
  145.  * 
  146.  * Revision 0.18  91/08/06  12:41:09  derek
  147.  * Edit list panel is done.  Still need to link it to the network code.
  148.  * 
  149.  * Revision 0.17  91/07/30  11:45:31  derek
  150.  * I have fixed the tmp file conflict bug.
  151.  * 
  152.  * Revision 0.16  91/07/27  11:45:47  derek
  153.  * I have added audio output options to the application.  User can choose
  154.  * either headphone or speaker as output device.
  155.  * 
  156.  * Revision 0.15  91/07/26  13:18:17  derek
  157.  * Some saving bugs fixed.
  158.  * 
  159.  * Revision 0.14  91/07/23  21:21:31  derek
  160.  * This version is not ready for release.  Disk space editing is half-done:
  161.  * the application can play an infinite sound and the canvases can handle
  162.  * infinite sound files.  The app is pretty bug free too, I think.  The
  163.  * weakness is that it cannot record sound infinitely.  
  164.  * 
  165.  * Revision 0.13  91/06/26  15:55:02  derek
  166.  * I have reformatted the code to conform coding specs.
  167.  * 
  168.  * Revision 0.12  91/06/20  19:55:19  derek
  169.  * The network part should be working.  Also fixed numerous minor parts
  170.  * involving the canvas and the display.
  171.  * 
  172.  * Revision 0.11  91/06/02  10:27:53  derek
  173.  * Changes made in the save-as function
  174.  * 
  175.  * Revision 0.10  1991/04/25  01:46:22  derek
  176.  * This version is checked in on 4/24/91
  177.  * */
  178. static char rcsid[] = "$Header: /Source/Media/collab/DTR/RCS/dtr.c,v 1.12 92/05/29 12:42:01 drapeau Exp $";
  179.  
  180. #include "dtr.h"              
  181. #include "dtr_ui.h"
  182. #include "getopt.h"
  183.  
  184. /*
  185.  * Instance XV_KEY_DATA key.  An instance is a set of related
  186.  * user interface objects.  A pointer to an object's instance
  187.  * is stored under this key in every object.  This must be a
  188.  * global variable.
  189.  */
  190. Attr_attribute    INSTANCE;
  191.  
  192. dtr_mainWindow_objects*            dtr_mainWindow;
  193. dtr_globalWaveCanvasPopUp_objects*    dtr_globalWaveCanvasPopUp;
  194. dtr_editListPanelPopUp_objects*        dtr_editListPanelPopUp;
  195. dtr_infoPopUp_objects*            dtr_infoPopUp;
  196.  
  197. extern Scrollbar            WaveCanvasScrollbar;
  198.  
  199. void
  200.   main(argc, argv)
  201. int        argc;
  202. char        **argv;
  203. {
  204.   Rect    tempRect;
  205.  
  206.   xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);            /*  Initialize XView.                               */
  207.   INSTANCE = xv_unique_key();
  208.   strcpy(prog, argv[0]);
  209.  
  210.   dtr_mainWindow =                            /*  Initialize user interface components.           */
  211.     dtr_mainWindow_objects_initialize(NULL, NULL);
  212.   dtr_globalWaveCanvasPopUp =
  213.     dtr_globalWaveCanvasPopUp_objects_initialize(NULL, dtr_mainWindow->mainWindow);
  214.   dtr_editListPanelPopUp =
  215.     dtr_editListPanelPopUp_objects_initialize(NULL, dtr_mainWindow->mainWindow);
  216.   dtr_infoPopUp =
  217.     dtr_infoPopUp_objects_initialize(NULL, dtr_mainWindow->mainWindow);
  218.   
  219.   frame_get_rect(dtr_mainWindow->mainWindow,&tempRect);        /* Get the size of the top-level window */
  220.   tempRect.r_top = 275;
  221.   tempRect.r_left = 30;
  222.   frame_set_rect(dtr_mainWindow->mainWindow,&tempRect);        /* Set the position of the top-level window */
  223.  
  224.   frame_get_rect(dtr_editListPanelPopUp->editListPanelPopUp,
  225.          &tempRect);
  226.   tempRect.r_top = 275;
  227.   tempRect.r_left = 640;
  228.   frame_set_rect(dtr_editListPanelPopUp->editListPanelPopUp,
  229.          &tempRect);
  230.  
  231.   frame_get_rect(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp,
  232.          &tempRect);
  233.   tempRect.r_top = 60;
  234.   tempRect.r_left = 200;
  235.   frame_set_rect(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp,
  236.          &tempRect);
  237.  
  238.   frame_get_rect(dtr_infoPopUp->infoPopUp,&tempRect);
  239.   tempRect.r_top = 250;
  240.   tempRect.r_left = 340;
  241.   frame_set_rect(dtr_infoPopUp->infoPopUp,&tempRect);
  242.  
  243.   InitOpenPanel();                            /*  Initialize the open panel stuff.                */
  244.   InitEditList();
  245.   InitWaveCanvasScrollbar();                        /*  Initialize the scrollbar for wave canvas.       */
  246.   InitScaleCanvasScrollbar();
  247.   InitWaveCanvas();
  248.   InitGlobalWaveCanvas();
  249.   InitVUMeterCanvas();
  250.   InitWaveEditVariables();
  251.   
  252.   (void) notify_set_signal_func((Notify_client)dtr_mainWindow,        /*  Set up to catch SIGPOLL asynchronously.         */
  253.                 (Notify_func)SigpollAsyncHandler, 
  254.                 SIGPOLL, NOTIFY_ASYNC); 
  255.   
  256.   (void) notify_set_event_func(SIGPOLL,                    /*  Set a synchronous event handler for SIGPOLL...  */
  257.                    (Notify_func)SigpollSyncHandler,        /*  ...to schedule.                                 */
  258.                    NOTIFY_SAFE);
  259.   
  260.   InitAudio();                                /*  Initialize audio parameters.                    */
  261.   InitAudioControl();                            /*  Initialize audio control device.                */
  262.   InitBuffer();                                /*  Initialize the sound buffer.                    */
  263.   InitRecord();                                /*  Initialize the recording tmp file name.         */
  264.   AudioUpdatePanel(TRUE);                        /*  Update audio control (by calling...             */
  265.                                     /*  ...AudioReadState().                            */
  266.   InitDisplay();                            /*  Set Initial display.                            */
  267.   InitNetwork(argc, argv);                        /*  Init networking stuff, set up connection...     */
  268.                                     /*  ...with PortManager.                            */
  269. /************
  270.   if (strcmp(currentSoundFile, "Untitled") != 0)
  271.   {
  272.   UpdateHeader(FALSE);
  273.     
  274.     FileReady = ReadSoundFile(FALSE);
  275.     SoundBufferReady = FALSE;                
  276.     SameSoundFile = TRUE;
  277.     if (FileReady) 
  278.     {
  279.       RepaintWaveCanvas();
  280.       RepaintGlobalWaveCanvas();
  281.     }
  282.   }
  283. ************/
  284.  
  285.   notify_interpose_destroy_func(dtr_mainWindow->mainWindow,
  286.                 DestroyMainWindow);
  287.  
  288.   xv_main_loop(dtr_mainWindow->mainWindow);            /*  Turn control over to XView.                     */
  289.   exit(0);
  290. }
  291.  
  292.  
  293.  
  294. /*
  295.  * Menu handler for `DocumentMenu (Open)'.
  296.  */
  297. Menu_item
  298.   OpenFileHandler(item, op)
  299. Menu_item    item;
  300. Menu_generate    op;
  301. {
  302.   switch (op) 
  303.   {
  304.    case MENU_DISPLAY:
  305.     break;
  306.     
  307.    case MENU_DISPLAY_DONE:
  308.     break;
  309.     
  310.    case MENU_NOTIFY:
  311.     Browse(NULL, BrowseOpen, IS_SOUNDFILE, NULL, NULL);
  312.     break;
  313.     
  314.    case MENU_NOTIFY_DONE:
  315.     break;
  316.   }
  317.   return item;
  318. }
  319.  
  320.  
  321. /*
  322.  * Menu handler for `DocumentMenu (Save Sound File)'.
  323.  */
  324. Menu_item
  325.   SaveSoundFileMenuOption(item, op)
  326. Menu_item    item;
  327. Menu_generate    op;
  328. {
  329.   char soundFileName[80];
  330.  
  331.   switch (op) 
  332.   {
  333.    case MENU_DISPLAY:
  334.     break;
  335.     
  336.    case MENU_DISPLAY_DONE:
  337.     break;
  338.     
  339.    case MENU_NOTIFY:
  340.     if ((strcmp(currentSoundFile, "Untitled") == 0) || IsTmpSoundFile(currentSoundFile))
  341.     {
  342.       Browse(NULL, BrowseSave, IS_SOUNDFILE, NULL, NULL);
  343.     }
  344.     else
  345.     {
  346.       Browse(currentSoundFile, BrowseCheckSave, IS_SOUNDFILE, NULL, NULL);
  347.     }
  348.     break;
  349.     
  350.    case MENU_NOTIFY_DONE:
  351.     break;
  352.   }
  353.   return item;
  354. }
  355.  
  356.  
  357. /*
  358.  * Menu handler for `DocumentMenu (Save Sound File As)'.
  359.  */
  360. Menu_item
  361. SaveSoundFileAsMenuOption(item, op)
  362.      Menu_item    item;
  363.      Menu_generate    op;
  364. {
  365.   switch (op) 
  366.   {
  367.    case MENU_DISPLAY:
  368.     break;
  369.     
  370.    case MENU_DISPLAY_DONE:
  371.     break;
  372.     
  373.    case MENU_NOTIFY:
  374.     Browse(NULL, BrowseSave, IS_SOUNDFILE, NULL, NULL);
  375.     break;
  376.     
  377.    case MENU_NOTIFY_DONE:
  378.     break;
  379.   }
  380.   return item;
  381. }
  382.  
  383.  
  384. /*
  385.  * Menu handler for `DocumentMenu (Info)'.
  386.  */
  387. Menu_item
  388.   InfoHandler(item, op)
  389. Menu_item    item;
  390. Menu_generate    op;
  391. {
  392.   switch (op) 
  393.   {
  394.    case MENU_DISPLAY:
  395.     break;
  396.     
  397.    case MENU_DISPLAY_DONE:
  398.     break;
  399.     
  400.    case MENU_NOTIFY:
  401.     xv_set(dtr_infoPopUp->infoPopUp, FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  402.     xv_set(dtr_infoPopUp->infoPopUp, XV_SHOW, TRUE, NULL);
  403.     break;
  404.     
  405.    case MENU_NOTIFY_DONE:
  406.     break;
  407.   }
  408.   return item;
  409. }
  410.  
  411.  
  412. /*
  413.  *  Menu handler for `DocumentMenu (Close)'.
  414.  *  This function closes the current document.  (Same as ClearAll.)
  415.  */
  416. Menu_item
  417. CloseHandler(item, op)
  418.     Menu_item    item;
  419.     Menu_generate    op;
  420. {
  421.   switch (op) {
  422.    case MENU_DISPLAY:
  423.     break;
  424.  
  425.    case MENU_DISPLAY_DONE:
  426.     break;
  427.  
  428.    case MENU_NOTIFY:
  429.     ClearAllSound();
  430.     break;
  431.  
  432.    case MENU_NOTIFY_DONE:
  433.     break;
  434.   }
  435.   return item;
  436. }
  437.  
  438.  
  439. /*
  440.  * Menu handler for `DocumentMenu (quit)'.
  441.  */
  442. Menu_item
  443.   QuitDtr(item, op)
  444. Menu_item    item;
  445. Menu_generate    op;
  446. {
  447.   int    reply;
  448.  
  449.   switch (op) 
  450.   {
  451.    case MENU_DISPLAY:
  452.     break;
  453.     
  454.    case MENU_DISPLAY_DONE:
  455.     break;
  456.     
  457.    case MENU_NOTIFY:
  458.     if (unsavedChangesExist == TRUE)
  459.     {
  460.       reply = notice_prompt(dtr_editListPanelPopUp->editListUpperControlPanel, NULL,
  461.                 NOTICE_MESSAGE_STRINGS,
  462.                 "Unsaved changes exist in your current edit list.",
  463.                 "Quit Anyway?",
  464.                 NULL,
  465.                 NOTICE_BUTTON, "Yes", 'Y',
  466.                 NOTICE_BUTTON, "Cancel", 'C',
  467.                 NULL);
  468.       if (reply == 'C')
  469.     return item;
  470.     }
  471.     if (BufferSaved == FALSE)
  472.     {
  473.       reply = notice_prompt(dtr_mainWindow->menuControlPanel, NULL,
  474.                 NOTICE_MESSAGE_STRINGS,
  475.                 "Buffer not saved yet.",
  476.                 "Quit Anyway?",
  477.                 NULL,
  478.                 NOTICE_BUTTON, "Yes", 'Y',
  479.                 NOTICE_BUTTON, "Cancel", 'C',
  480.                 NULL);
  481.       if (reply == 'C')
  482.     return item;
  483.     }
  484.     AudioFlushClose();
  485.     RemoveSoundFileInTmp();
  486.     SenderDisconnectFromPortMgr(sender, &(receiver->receivePort));
  487.     exit(0);
  488.     break;
  489.     
  490.    case MENU_NOTIFY_DONE:
  491.     break;
  492.   }
  493.   return item;
  494. }                                    /* end function QuitDtr */
  495.  
  496.  
  497. /*
  498.  * Menu handler for `EditMenu (Cut)'.
  499.  */
  500. Menu_item
  501.   CutHandler(item, op)
  502. Menu_item    item;
  503. Menu_generate    op;
  504. {
  505.   switch (op) 
  506.   {
  507.    case MENU_DISPLAY:
  508.    case MENU_DISPLAY_DONE:
  509.    case MENU_NOTIFY_DONE:
  510.     break;
  511.     
  512.    case MENU_NOTIFY:
  513.     if (WaveEditMode == FALSE)
  514.     {
  515.       break;
  516.     }
  517.     WaveCutHandler();
  518.     break;
  519.   }
  520.   return item;
  521. }
  522.  
  523.  
  524. /*
  525.  * Menu handler for `EditMenu (Copy)'.
  526.  */
  527. Menu_item
  528.   CopyHandler(item, op)
  529. Menu_item    item;
  530. Menu_generate    op;
  531. {
  532.   extern    BOOL    AboutToCopy;
  533.   
  534.   switch (op) 
  535.   {
  536.    case MENU_DISPLAY:
  537.    case MENU_DISPLAY_DONE:
  538.    case MENU_NOTIFY_DONE:
  539.     break;
  540.     
  541.    case MENU_NOTIFY:
  542.     if (WaveEditMode == FALSE)
  543.     {
  544.       break;
  545.     }
  546.     AboutToCopy = TRUE;
  547.     break;
  548.     
  549.   }
  550.   return item;
  551. }
  552.  
  553.  
  554. /*
  555.  * Menu handler for `EditMenu (Undo)'.
  556.  */
  557. Menu_item
  558.   UndoHandler(item, op)
  559. Menu_item    item;
  560. Menu_generate    op;
  561. {
  562.   unsigned char  *tempptr;
  563.   unsigned        tempu;
  564.   int             tempi;
  565.   extern   BOOL   CanUndo;
  566.   
  567.   switch (op) 
  568.   {
  569.    case MENU_DISPLAY:
  570.    case MENU_NOTIFY_DONE:
  571.    case MENU_DISPLAY_DONE:
  572.     break;
  573.     
  574.    case MENU_NOTIFY:
  575.     if (WaveEditMode == FALSE)
  576.     {
  577.       break;
  578.     }
  579.     if (!CanUndo)
  580.       break;
  581.     if (Buffer.olddata) 
  582.     {
  583.       ClearAllSound();
  584.       
  585.       tempptr = Buffer.data;
  586.       Buffer.data = Buffer.olddata;
  587.       Buffer.olddata = tempptr;
  588.       
  589.       tempu = Buffer.alloc_size;
  590.       Buffer.alloc_size = Buffer.old_alloc_size;
  591.       Buffer.old_alloc_size = tempu;
  592.       
  593.       tempi = Buffer.hdr.data_size;
  594.       Buffer.hdr.data_size = Buffer.old_hdr_data_size;
  595.       Buffer.old_hdr_data_size = tempi;
  596.       
  597.       SoundBufferReady = TRUE;
  598.       Buffer.display.start = Buffer.play.start = 0;
  599.       Buffer.display.end = Buffer.play.end = 
  600.     Buffer.hdr.data_size - 1;
  601.       FileUpdate();
  602.       UpdateMessageDisplay();
  603.       Zoom = 1.0;
  604.       UpdateZoomLevelDisplay();
  605.       
  606.       oldLeftFloatMarker = 0.0;                        /*  Reset Markers                                   */
  607.       oldRightFloatMarker = (double) Buffer.hdr.data_size - 1.0;
  608.       WaveCanvasRightMarkerSet = FALSE;
  609.       oldLeftFloatGbWaveMarker = 0.0;
  610.       oldRightFloatGbWaveMarker = 
  611.     (double) Buffer.hdr.data_size - 1.0;
  612.       GlobalWaveCanvasRightMarkerSet = FALSE;
  613.       RepaintWaveCanvas();
  614.       RepaintGlobalWaveCanvas();
  615.       
  616.       SameSoundFile = TRUE;                        /*  Reset Same Sound File flag.                     */
  617.     }
  618.     else 
  619.     {
  620.     AlertByNoticePrompt(dtr_mainWindow->menuControlPanel,
  621.                 "Cannot undo any further.");
  622.     }
  623.     break;
  624.   }
  625.   return item;
  626. }                                    /* end function UndoHandler */
  627.  
  628.  
  629. /*
  630.  * Menu handler for `EditMenu (Paste)'.
  631.  */
  632. Menu_item
  633.   PasteHandler(item, op)
  634. Menu_item    item;
  635. Menu_generate    op;
  636. {
  637.   extern    BOOL    AboutToPaste;
  638.   
  639.   switch (op) 
  640.   {
  641.    case MENU_DISPLAY:
  642.    case MENU_DISPLAY_DONE:
  643.    case MENU_NOTIFY_DONE:
  644.     break;
  645.     
  646.    case MENU_NOTIFY:
  647.     if (WaveEditMode == FALSE)
  648.     {
  649.       break;
  650.     }
  651.     AboutToPaste = TRUE;
  652.     break;
  653.   }
  654.   return item;
  655. }
  656.  
  657.  
  658. /*
  659.  * Menu handler for `EditMenu (Clear All)'.
  660.  */
  661. Menu_item
  662.   ClearAllHandler(item, op)
  663. Menu_item    item;
  664. Menu_generate    op;
  665. {
  666.   switch (op) 
  667.   {
  668.    case MENU_DISPLAY:
  669.    case MENU_DISPLAY_DONE:
  670.    case MENU_NOTIFY_DONE:
  671.     break;
  672.     
  673.    case MENU_NOTIFY:
  674.     ClearAllSound();
  675.     break;
  676.     
  677.   }
  678.   return item;
  679. }
  680.  
  681.  
  682. /*
  683.  * Menu handler for `OptionsMenu (Reset Markers)'.
  684.  */
  685. Menu_item
  686.   ResetMarkersHandler(item, op)
  687. Menu_item    item;
  688. Menu_generate    op;
  689. {
  690.   if (op == MENU_NOTIFY) 
  691.   {
  692.     if (WaveCanvasRightMarkerSet)
  693.       ResetWaveCanvasMarkers();
  694.     if (GlobalWaveCanvasRightMarkerSet)
  695.       ResetGlobalWaveCanvasMarkers();
  696.   }
  697.   return item;
  698. }
  699.  
  700.  
  701. /*
  702.  * Menu handler for `OptionsMenu (Size To Fit)'.
  703.  */
  704. Menu_item
  705.   SizeToFitHandler(item, op)
  706. Menu_item    item;
  707. Menu_generate    op;
  708. {
  709.   double             newZoom;
  710.   double             save;
  711.   
  712.   save = WaveCanvasDataSamplingInterval;
  713.   
  714.   switch (op) 
  715.   {
  716.    case MENU_DISPLAY:
  717.    case MENU_DISPLAY_DONE:
  718.    case MENU_NOTIFY_DONE:
  719.     break;
  720.     
  721.    case MENU_NOTIFY:
  722.     
  723.     if ((FileReady == FALSE) && (SoundBufferReady == FALSE))        /*  If no sound has been loaded yet, return...      */
  724.     {                                    /*  ...doing anything.                              */
  725.       AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  726.               "There is no sound to fit.");
  727.       return item;
  728.     }
  729.   
  730.     if (WaveCanvasRightMarkerSet)                    /*  Adjust the zoom level.                          */
  731.     {
  732.       WaveCanvasDataSamplingInterval = 
  733.     (oldRightFloatMarker - oldLeftFloatMarker) / WaveWindowWidth;
  734.     }
  735.     else 
  736.     {
  737.       WaveCanvasDataSamplingInterval = Buffer.hdr.data_size /        /*  If no selection is specified, we still want...  */
  738.     (double) WaveWindowWidth;                    /*  ...to resize the whole canvas.                  */
  739.     }
  740.     
  741.     newZoom = DefaultWaveCanvasDataSamplingInterval / 
  742.       WaveCanvasDataSamplingInterval;
  743.     
  744.     if (newZoom > (double) MAX_ZOOM) 
  745.     {
  746.       AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  747.               "Selection is too small to resize.");
  748.       WaveCanvasDataSamplingInterval = save;
  749.       return item;
  750.     }
  751.     else Zoom = newZoom;
  752.     
  753.     UpdateZoomLevelDisplay();
  754.     WaveCanvasDataSamplingInterval = DefaultWaveCanvasDataSamplingInterval /
  755.       Zoom;
  756. /******
  757.     FrameStartingSecond = (oldLeftFloatMarker /
  758.                DefaultWaveCanvasDataSamplingInterval) /
  759.                  (WaveWindowWidth / 2)) * 5.0;
  760. ********/
  761.     FrameStartingSecond = (oldLeftFloatMarker /
  762.                DEVICE_SAMPLE_RATE);
  763.     RepaintWaveCanvas();
  764.     
  765.     if (WaveCanvasRightMarkerSet) 
  766.     {
  767.       xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 
  768.          irint(((oldLeftFloatMarker - (FrameStartingSecond * DEVICE_SAMPLE_RATE))/ 
  769.             WaveCanvasDataSamplingInterval)
  770.            / 10.0), NULL);
  771.     }
  772.     else 
  773.     {
  774.       xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  775.     }
  776.     UpdateCanvasFrame();
  777.     break;
  778.   }
  779.   return item;
  780. }                                    /* end function SizeToFitHandler */
  781.  
  782.  
  783. /*
  784.  * Menu handler for `OptionsMenu (Global Wave Canvas)'.
  785.  */
  786. Menu_item
  787.   GlobalWaveCanvasHandler(item, op)
  788. Menu_item    item;
  789. Menu_generate    op;
  790. {
  791.   switch (op) 
  792.   {
  793.    case MENU_DISPLAY:
  794.     break;
  795.     
  796.    case MENU_DISPLAY_DONE:
  797.     break;
  798.     
  799.    case MENU_NOTIFY:
  800.     xv_set(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, 
  801.        FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  802.     xv_set(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, 
  803.        XV_SHOW, TRUE, NULL);
  804.     break;
  805.     
  806.    case MENU_NOTIFY_DONE:
  807.     break;
  808.   }
  809.   return item;
  810. }
  811.  
  812.  
  813. /*
  814.  * Menu handler for `optionsMenu (Enable Sound Editing)'.
  815.  */
  816. Menu_item
  817.   ToggleSoundEditing(item, op)
  818. Menu_item    item;
  819. Menu_generate    op;
  820. {
  821.   dtr_mainWindow_objects * ip = (dtr_mainWindow_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  822.   
  823.   switch (op)
  824.   {
  825.    case MENU_DISPLAY:
  826.     break;
  827.     
  828.    case MENU_DISPLAY_DONE:
  829.     break;
  830.     
  831.    case MENU_NOTIFY:
  832.     if (WaveEditMode == TRUE)
  833.     {
  834.       WaveEditMode = FALSE;
  835.       xv_set(item, MENU_STRING, "Enable Sound Editing",NULL);
  836.     }
  837.     else
  838.     {
  839.       WaveEditMode = TRUE;
  840.       xv_set(item, MENU_STRING, "Disable Sound Editing",NULL);
  841.     }
  842.     break;
  843.     
  844.    case MENU_NOTIFY_DONE:
  845.     break;
  846.   }
  847.   return item;
  848. }
  849.  
  850.  
  851. /*
  852.  * Menu handler for `audioOutputOptionsMenu (icons/speaker.icon)'.
  853.  */
  854. Menu_item
  855.   SetSpeakerOutput(item, op)
  856. Menu_item    item;
  857. Menu_generate    op;
  858. {
  859.   static int    playPort;
  860.   
  861.   switch (op)
  862.   {
  863.    case MENU_DISPLAY:
  864.     break;
  865.     
  866.    case MENU_DISPLAY_DONE:
  867.     break;
  868.     
  869.    case MENU_NOTIFY:
  870.     playPort = AUDIO_SPEAKER;
  871.     audio_set_play_port(Audioctl_fd, &playPort);
  872.     break;
  873.     
  874.    case MENU_NOTIFY_DONE:
  875.     break;
  876.   }
  877.   return item;
  878. }
  879.  
  880.  
  881. /*
  882.  * Menu handler for `audioOutputOptionsMenu (icons/headphone.icon)'.
  883.  */
  884. Menu_item
  885.   SetHeadphoneOutput(item, op)
  886. Menu_item    item;
  887. Menu_generate    op;
  888. {
  889.   static int    playPort;
  890.   
  891.   switch (op)
  892.   {
  893.    case MENU_DISPLAY:
  894.     break;
  895.     
  896.    case MENU_DISPLAY_DONE:
  897.     break;
  898.     
  899.    case MENU_NOTIFY:
  900.     playPort = AUDIO_HEADPHONE;
  901.     audio_set_play_port(Audioctl_fd, &playPort);
  902.     break;
  903.     
  904.    case MENU_NOTIFY_DONE:
  905.     break;
  906.   }
  907.   return item;
  908. }
  909.  
  910.  
  911.  
  912. /*
  913.  * Notify callback function for `openEditListButton'.
  914.  */
  915. void
  916. ShowEditListPanelHandler(item, event)
  917.     Panel_item    item;
  918.     Event        *event;
  919. {
  920.   xv_set(dtr_editListPanelPopUp->editListPanelPopUp,
  921.      FRAME_CMD_PUSHPIN_IN, TRUE, NULL);
  922.   xv_set(dtr_editListPanelPopUp->editListPanelPopUp,
  923.      XV_SHOW, TRUE, NULL);
  924. }
  925.  
  926.  
  927.  
  928.  
  929. /*
  930.  * Menu handler for `EditListDocumentMenu (Open)'.
  931.  */
  932. Menu_item
  933. OpenEditListHandler(item, op)
  934.     Menu_item    item;
  935.     Menu_generate    op;
  936. {
  937.   switch (op) {
  938.    case MENU_DISPLAY:
  939.     break;
  940.     
  941.    case MENU_DISPLAY_DONE:
  942.     break;
  943.     
  944.    case MENU_NOTIFY:
  945.     Browse(NULL, BrowseOpen, IS_EDITLIST, documentFirstLine, documentFileType);
  946.     break;
  947.     
  948.    case MENU_NOTIFY_DONE:
  949.     break;
  950.   }
  951.   return item;
  952. }
  953.  
  954.  
  955. /*
  956.  * Menu handler for `EditListDocumentMenu (Save Edit List)'.
  957.  */
  958. Menu_item
  959.   SaveEditListHandler(item, op)
  960. Menu_item    item;
  961. Menu_generate    op;
  962. {
  963.   switch (op)
  964.   {
  965.    case MENU_DISPLAY:
  966.     break;
  967.     
  968.    case MENU_DISPLAY_DONE:
  969.     break;
  970.     
  971.    case MENU_NOTIFY:
  972.     if (strcmp(absoluteEditListName, "Untitled") == 0)            /* No filename specified yet */
  973.     {
  974.       Browse(NULL, BrowseSave, IS_EDITLIST, documentFirstLine, documentFileType);
  975.     }
  976.     else
  977.     {
  978.       Browse(absoluteEditListName, BrowseCheckSave, IS_EDITLIST,
  979.          documentFirstLine, documentFileType);
  980.     }
  981.     break;
  982.     
  983.    case MENU_NOTIFY_DONE:
  984.     break;
  985.   }
  986.   return item;
  987. }
  988.  
  989.  
  990.  
  991. /*
  992.  * Menu handler for `EditListDocumentMenu (Save Edit List As)'.
  993.  */
  994. Menu_item
  995. EditListSaveAsHandler(item, op)
  996.     Menu_item    item;
  997.     Menu_generate    op;
  998. {
  999.   switch (op) {
  1000.    case MENU_DISPLAY:
  1001.     break;
  1002.     
  1003.    case MENU_DISPLAY_DONE:
  1004.     break;
  1005.     
  1006.    case MENU_NOTIFY:
  1007.     Browse(NULL, BrowseSave, IS_EDITLIST, documentFirstLine, documentFileType);
  1008.     break;
  1009.     
  1010.    case MENU_NOTIFY_DONE:
  1011.     break;
  1012.   }
  1013.   return item;
  1014. }
  1015.  
  1016.  
  1017. /*
  1018.  * Menu handler for `EditListDocumentMenu (New)'.
  1019.  */
  1020. Menu_item
  1021. NewEditListHandler(item, op)
  1022.     Menu_item    item;
  1023.     Menu_generate    op;
  1024. {
  1025.   switch (op) {
  1026.    case MENU_DISPLAY:
  1027.     break;
  1028.     
  1029.    case MENU_DISPLAY_DONE:
  1030.     break;
  1031.     
  1032.    case MENU_NOTIFY:
  1033.     NewEditList();
  1034.     break;
  1035.     
  1036.    case MENU_NOTIFY_DONE:
  1037.     break;
  1038.   }
  1039.   return item;
  1040. }
  1041.  
  1042.  
  1043.  
  1044. /*
  1045.  * Notify callback function for `CanvasRewind2Button'.
  1046.  */
  1047. void
  1048. CanvasRewind2Handler(item, event)
  1049.     Panel_item    item;
  1050.     Event        *event;
  1051. {
  1052.   if (FrameStartingSecond == 0.0)
  1053.   {
  1054.     return;
  1055.   }
  1056.   else if (FrameStartingSecond >= 5.0)
  1057.   {
  1058.     FrameStartingSecond -= 10.0;
  1059.     if (FrameStartingSecond < 0.0)
  1060.       FrameStartingSecond = 0.0;
  1061.     RepaintWaveCanvas();
  1062.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1063.     UpdateCanvasFrame();
  1064.   }
  1065.   else 
  1066.   {
  1067.     FrameStartingSecond = 0.0;
  1068.     RepaintWaveCanvas();
  1069.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1070.     UpdateCanvasFrame();
  1071.   }    
  1072. }
  1073.  
  1074.  
  1075. /*
  1076.  * Notify callback function for `CanvasRewind1Button'.
  1077.  */
  1078. void
  1079.   CanvasRewind1Handler(item, event)
  1080. Panel_item    item;
  1081. Event        *event;
  1082. {
  1083.   if (FrameStartingSecond == 0.0)
  1084.   {
  1085.     return;
  1086.   }
  1087.   else  if (FrameStartingSecond >= 5.0)
  1088.   {
  1089.     FrameStartingSecond -= 5.0;
  1090.     RepaintWaveCanvas();
  1091.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1092.     UpdateCanvasFrame();
  1093.   }
  1094.   else
  1095.   {
  1096.     FrameStartingSecond = 0.0;
  1097.     RepaintWaveCanvas();
  1098.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1099.     UpdateCanvasFrame();
  1100.   }
  1101. }
  1102.  
  1103.  
  1104. /*
  1105.  * Notify callback function for `CanvasFastForward1Button'.
  1106.  */
  1107. void
  1108.   CanvasFastForward1Handler(item, event)
  1109. Panel_item    item;
  1110. Event        *event;
  1111. {
  1112.   double        duration;
  1113.     
  1114.   duration = Buffer.hdr.data_size / ((double) DEVICE_SAMPLE_RATE);
  1115.   if (duration > FrameStartingSecond + 5.0)
  1116.   {
  1117.     FrameStartingSecond += 5.0;
  1118.     RepaintWaveCanvas();
  1119.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1120.     UpdateCanvasFrame();
  1121.   }
  1122. }
  1123.  
  1124.  
  1125. /*
  1126.  * Notify callback function for `CanvasFastForward2Button'.
  1127.  */
  1128. void
  1129.   CanvasFastForward2Handler(item, event)
  1130. Panel_item    item;
  1131. Event        *event;
  1132. {
  1133.   double   duration;
  1134.     
  1135.   duration = Buffer.hdr.data_size / ((double) DEVICE_SAMPLE_RATE);
  1136.   if (duration > FrameStartingSecond + 10.0)
  1137.   {
  1138.     FrameStartingSecond += 10.0;
  1139.     if (duration < FrameStartingSecond)
  1140.       FrameStartingSecond -= 5.0;
  1141.     RepaintWaveCanvas();
  1142.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);
  1143.     UpdateCanvasFrame();
  1144.   }
  1145. }
  1146.  
  1147.  
  1148.  
  1149. /*
  1150.  * Event callback function for `WaveCanvas'.
  1151.  */
  1152. Notify_value
  1153.   WaveCanvasEventHandler(win, event, arg, type)
  1154. Xv_window    win;
  1155. Event        *event;
  1156. Notify_arg    arg;
  1157. Notify_event_type type;
  1158. {
  1159.   static     int     sawLeftDown = 0;
  1160.   static     int     sawMiddleDown = 0;
  1161.   static     int    lastWinX;
  1162.   int                   GbWaveWinX;
  1163.   int                   overallWaveWinX;
  1164.   extern        BOOL    AboutToCopy;
  1165.   extern    BOOL    AboutToPaste;
  1166.   extern    BOOL    CutPortionReady;
  1167.   
  1168.   if (ActiveFlag)                            /*  If playing or recording, return w/o doing...    */
  1169.     return notify_next_event_func(win, (Notify_event) event,        /*  ...anything.                                    */
  1170.                   arg, type);
  1171.   if (AboutToCopy)                            /*  Check if the mouse click is meant to be a ...   */
  1172.   {                                    /*  ...copy-click.                                  */
  1173.     if (WaveCanvasRightMarkerSet && (event_id(event) == MS_RIGHT ||
  1174.                      event_id(event) == MS_MIDDLE ||
  1175.                      event_id(event) == MS_LEFT))
  1176.       WaveCopyHandler(irint(event_x(event) * 
  1177.                 WaveCanvasDataSamplingInterval));
  1178.     return notify_next_event_func(win, (Notify_event) event, 
  1179.                   arg, type);
  1180.   }
  1181.   if (AboutToPaste)                            /*  Check if the mouse click is meant to be a ...   */
  1182.   {                                    /*  ...paste-click.                                 */
  1183.     if (CutPortionReady && (event_id(event) == MS_RIGHT ||
  1184.                 event_id(event) == MS_MIDDLE ||
  1185.                 event_id(event) == MS_LEFT))
  1186.       WavePasteHandler(irint(event_x(event) * 
  1187.                  WaveCanvasDataSamplingInterval));
  1188.     return notify_next_event_func(win, (Notify_event) event, 
  1189.                   arg, type);
  1190.   }
  1191.   overallWaveWinX = irint(event_x(event) +
  1192.               ((FrameStartingSecond / 10.0) * WaveWindowWidth
  1193.                * DefaultWaveCanvasDataSamplingInterval /
  1194.                WaveCanvasDataSamplingInterval));
  1195.   
  1196.   if (GlobalWaveCanvasDataSamplingInterval != 0.0)
  1197.     GbWaveWinX = irint(overallWaveWinX * 
  1198.                WaveCanvasDataSamplingInterval/
  1199.                GlobalWaveCanvasDataSamplingInterval);
  1200.   else GbWaveWinX = 0;
  1201.   if (event_id(event) == MS_LEFT)
  1202.   {
  1203.     if (event_is_down(event)) 
  1204.     {
  1205.       sawLeftDown = 1;
  1206.       leftButtonHoldPoint = overallWaveWinX;
  1207.       GbWaveLeftButtonHoldPoint = GbWaveWinX;
  1208.       WaveCanvasMarkerHandler(overallWaveWinX, &oldLeftFloatMarker);
  1209.       WaveCanvasMarkerHandler(overallWaveWinX, &oldRightFloatMarker);
  1210.       
  1211.       GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1212.                     &oldLeftFloatGbWaveMarker);
  1213.       GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1214.                     &oldRightFloatGbWaveMarker);
  1215.     }
  1216.     else if (event_is_up(event)) 
  1217.     {
  1218.       sawLeftDown = 0;
  1219.     }
  1220.   }                                    /* end if (event_id(event) == MS_LEFT) */
  1221.   else if (event_id(event) == MS_MIDDLE)
  1222.   {
  1223.     if (event_is_down(event))
  1224.     {
  1225.       sawMiddleDown = 1;
  1226.       if (leftButtonHoldPoint == NOTREADY)
  1227.       {
  1228.     leftButtonHoldPoint = overallWaveWinX;
  1229.     GbWaveLeftButtonHoldPoint = GbWaveWinX;
  1230.     WaveCanvasMarkerHandler(overallWaveWinX, &oldLeftFloatMarker);
  1231.     WaveCanvasMarkerHandler(overallWaveWinX, &oldRightFloatMarker);
  1232.     GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1233.                       &oldLeftFloatGbWaveMarker);
  1234.     GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1235.                       &oldRightFloatGbWaveMarker);
  1236.       }                                    /* end if (leftButtonHoldPoint == NOTREADY)  */
  1237.       else 
  1238.       {
  1239.     if (overallWaveWinX < leftButtonHoldPoint)
  1240.     {
  1241.       /***
  1242.         if (lastWinX > leftButtonHoldPoint)  {
  1243.         WaveCanvasMarkerHandler(leftButtonHoldPoint, 
  1244.         &oldRightFloatMarker);
  1245.         GlobalWaveCanvasMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1246.         &oldRightFloatGbWaveMarker);
  1247.         }
  1248.         **********/
  1249.       WaveCanvasBackwardMarkerHandler(overallWaveWinX, 
  1250.                       &oldLeftFloatMarker);
  1251.       GlobalWaveCanvasBackwardMarkerHandler(GbWaveWinX, 
  1252.                         &oldLeftFloatGbWaveMarker);
  1253.     }                                /* end if (overallWaveWinX < leftButtonHoldPoint) */
  1254.     else 
  1255.     {
  1256.       if (lastWinX < leftButtonHoldPoint)  
  1257.       {
  1258.         WaveCanvasBackwardMarkerHandler(leftButtonHoldPoint, 
  1259.                         &oldLeftFloatMarker);
  1260.         GlobalWaveCanvasBackwardMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1261.                           &oldLeftFloatGbWaveMarker);
  1262.       }
  1263.       WaveCanvasMarkerHandler(overallWaveWinX, &oldRightFloatMarker);
  1264.       GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1265.                     &oldRightFloatGbWaveMarker);
  1266.     }                                /* end else (overallWaveWinX < leftButtonHoldPoint) */
  1267.       }                                    /* end else (leftButtonHoldPoint == NOTREADY) */
  1268.     }                                    /* end if (event_is_down(event)) */
  1269.     else if (event_is_up(event)) 
  1270.     {
  1271.       sawMiddleDown = 0;
  1272.     }
  1273.   }                                    /* end else if (event_id(event) == MS_MIDDLE) */
  1274.   else if (event_id(event) == LOC_DRAG && (sawLeftDown || sawMiddleDown)) 
  1275.   {
  1276.     if (overallWaveWinX < leftButtonHoldPoint)
  1277.     {
  1278.       if (lastWinX > leftButtonHoldPoint)  
  1279.       {
  1280.     WaveCanvasMarkerHandler(leftButtonHoldPoint, 
  1281.                 &oldRightFloatMarker);
  1282.     GlobalWaveCanvasMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1283.                       &oldRightFloatGbWaveMarker);
  1284.       }
  1285.       WaveCanvasBackwardMarkerHandler(overallWaveWinX, &oldLeftFloatMarker);
  1286.       GlobalWaveCanvasBackwardMarkerHandler(GbWaveWinX, 
  1287.                         &oldLeftFloatGbWaveMarker);
  1288.     }                                    /* end if (overallWaveWinX < leftButtonHoldPoint) */
  1289.     else
  1290.     {
  1291.       if (lastWinX < leftButtonHoldPoint) 
  1292.       {
  1293.     WaveCanvasBackwardMarkerHandler(leftButtonHoldPoint,
  1294.                     &oldLeftFloatMarker);
  1295.     GlobalWaveCanvasBackwardMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1296.                           &oldLeftFloatGbWaveMarker);
  1297.       }
  1298.       WaveCanvasMarkerHandler(overallWaveWinX, &oldRightFloatMarker);
  1299.       GlobalWaveCanvasMarkerHandler(GbWaveWinX, 
  1300.                     &oldRightFloatGbWaveMarker);
  1301.     }                                    /* end else (overallWaveWinX < leftButtonHoldPoint) */
  1302.   }
  1303.   lastWinX = overallWaveWinX;
  1304.   UpdateSelection();                            /* Load new selection info into the Edit List panel */
  1305.   return notify_next_event_func(win, (Notify_event) event, arg, type);
  1306. }                                    /* end function WaveCanvasEventHandler */
  1307.  
  1308.  
  1309. /*
  1310.  * Repaint callback function for `WaveCanvas'.
  1311.  */
  1312. void
  1313.   WaveCanvasRepaintHandler(canvas, paint_window, display, xid, rects)
  1314. Canvas        canvas;
  1315. Xv_window    paint_window;
  1316. Display        *display;
  1317. Window        xid;
  1318. Xv_xrectlist    *rects;
  1319. {
  1320.   int              pt;
  1321.   int              i;
  1322.   int              from, to;
  1323.   extern   GC         gcWave;
  1324.   extern   Scrollbar    WaveCanvasScrollbar;
  1325.   int              heightOffset;
  1326.   double           floatpt;
  1327.   int              leftWinX, rightWinX;
  1328.   double                scaleMarkerInterval;
  1329.   double                x;
  1330.   static unsigned char  soundData[80000];
  1331.   int                   canvasDataSize;
  1332.   
  1333.   XClearWindow(display, xid);
  1334.   
  1335.   WaveCanvasDataSamplingInterval = DefaultWaveCanvasDataSamplingInterval /
  1336.     Zoom;
  1337.   UpdateCanvasesAndScrollbarParameters();
  1338.   if (Buffer.hdr.data_size < (FrameStartingSecond + 10) * DEVICE_SAMPLE_RATE)
  1339.   {
  1340.     canvasDataSize = Buffer.hdr.data_size -                /*  find out how much data to display over one...   */
  1341.       irint(FrameStartingSecond * DEVICE_SAMPLE_RATE);            /*  ...window.                                      */
  1342.   }
  1343.   else
  1344.   {
  1345.     canvasDataSize = 80000;
  1346.   }
  1347.   
  1348.   if (FileReady)
  1349.   {
  1350.     soundfd = open(Buffer.filename, O_RDONLY);
  1351.     lseek(soundfd, irint(FrameStartingSecond * DEVICE_SAMPLE_RATE), L_SET);
  1352.     read(soundfd, (char *)soundData, canvasDataSize);
  1353.     close(soundfd);
  1354.   }
  1355.   
  1356.   heightOffset = (int) (WaveCanvasMidHeight - 15);
  1357.   WaveCanvasPenColor("White");
  1358.   to = heightOffset;
  1359.   
  1360.   if (FileReady)                            /*  Canvas data size is defined to be the diff...   */
  1361.   {                                    /*  between last byte of the data and the closest.. */
  1362.     floatpt = 0.0;                            /*  ...multiple of 80000.                           */
  1363.     for(i=0, pt=0 ; pt < canvasDataSize && i < WaveCanvasWidth;
  1364.     i++)
  1365.     {
  1366.       from = to;
  1367.       to   = ((audio_u2c(soundData[pt]) * WaveScopeWidth) >> 7)
  1368.     + heightOffset;
  1369.       
  1370.       XDrawLine(display, xid, gcWave, i-1, from, i, to);
  1371.       
  1372.       floatpt = floatpt + WaveCanvasDataSamplingInterval;
  1373.       pt = irint(floatpt);
  1374.     }
  1375.   }    
  1376.   else if (SoundBufferReady == TRUE)
  1377.   {
  1378.     floatpt = (double) FrameStartingSecond * DEVICE_SAMPLE_RATE;
  1379.     
  1380.     for(i=0, pt= irint(floatpt) ;
  1381.     pt < canvasDataSize + (FrameStartingSecond * DEVICE_SAMPLE_RATE)
  1382.     && i <= WaveCanvasWidth;
  1383.     i++)
  1384.     {
  1385.       from = to;
  1386.       to   = ((audio_u2c(Buffer.data[pt]) * WaveScopeWidth) >> 7)
  1387.     + heightOffset;
  1388.       
  1389.       XDrawLine(display, xid, gcWave, i-1, from, i, to);
  1390.       
  1391.       floatpt = floatpt + WaveCanvasDataSamplingInterval;
  1392.       pt = irint(floatpt);
  1393.     }
  1394.   }
  1395.   
  1396.   scaleMarkerInterval = WaveWindowWidth / 10.0 * Zoom;            /*  Draw the horizontal time axis.                  */
  1397.   WaveCanvasPenColor("Red");
  1398.   
  1399.   XDrawLine(display, xid, gcWave, 0, WaveCanvasMidHeight-15, 
  1400.         WaveCanvasWidth, WaveCanvasMidHeight-15);
  1401.   for(x = 0.0 ; x < (double) WaveCanvasWidth ; x += scaleMarkerInterval)
  1402.     XDrawLine(display, xid, gcWave, 
  1403.           irint(x), WaveCanvasMidHeight-15+5,
  1404.           irint(x), WaveCanvasMidHeight-15-5);
  1405.   
  1406.   if (WaveCanvasRightMarkerSet)                        /*  Highlignt marked area.                          */
  1407.   {
  1408.     rightWinX = irint(oldRightFloatMarker/WaveCanvasDataSamplingInterval);
  1409.     leftWinX  = irint(oldLeftFloatMarker/WaveCanvasDataSamplingInterval);
  1410.     ReverseWaveCanvasArea(leftWinX, rightWinX);
  1411.   }
  1412. }                                    /* end function WaveCanvasRepaintHandler */
  1413.  
  1414.  
  1415. /*
  1416.  * Notify callback function for `PauseButton'.
  1417.  */
  1418. void
  1419.   PauseButtonHandler(item, event)
  1420. Panel_item    item;
  1421. Event        *event;
  1422. {
  1423.   Pause();
  1424. }
  1425.  
  1426.  
  1427. /*
  1428.  * Notify callback function for `StopButton'.
  1429.  */
  1430. void
  1431.   StopButtonHandler(item, event)
  1432. Panel_item    item;
  1433. Event        *event;
  1434. {
  1435.   if (ActiveFlag & PLAY)
  1436.     StopPlay();
  1437.   else
  1438.     if (ActiveFlag & RECORD)
  1439.       StopRecord();
  1440.   CancelButtonGlow();
  1441. }
  1442.  
  1443.  
  1444. /*
  1445.  * Notify callback function for `PlayButton'.
  1446.  */
  1447. void
  1448.   PlayButtonHandler(item, event)
  1449. Panel_item    item;
  1450. Event        *event;
  1451. {
  1452.   dtr_mainWindow_objects    *ip = 
  1453.     (dtr_mainWindow_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  1454.   
  1455.   if (ActiveFlag & PLAY)                        /* Don't do anything if already playing a sound */
  1456.     return;
  1457.   if (WaitFlag & PLAY) 
  1458.   {
  1459.     AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  1460.             "Device is not ready.  Play Stopped");
  1461.     StopPlay();
  1462.     return;
  1463.   }
  1464.   
  1465.   if (WaveEditMode == FALSE)
  1466.   {
  1467.     FileReady = ReadSoundFile(FALSE);
  1468.     SoundBufferReady = FALSE;
  1469.   }
  1470.   else 
  1471.   {
  1472.     SoundBufferReady = ReadSoundFile(TRUE);
  1473.     FileReady = FALSE;
  1474.   }
  1475.   
  1476.   if((SoundBufferReady == TRUE) || (FileReady == TRUE)) 
  1477.   {
  1478.     if (!SameSoundFile)  
  1479.     {
  1480.       RepaintWaveCanvas(); 
  1481.       RepaintGlobalWaveCanvas();
  1482.     }
  1483.     Play(ip);
  1484.     SameSoundFile = TRUE;
  1485.   }
  1486. }                                    /* end function PlayButtonHandler */
  1487.  
  1488.  
  1489.  
  1490. /*
  1491.  * Repaint callback function for `ScaleCanvas'.
  1492.  */
  1493. void
  1494.   ScaleCanvasRepaintHandler(canvas, paint_window, display, xid, rects)
  1495. Canvas        canvas;
  1496. Xv_window    paint_window;
  1497. Display        *display;
  1498. Window        xid;
  1499. Xv_xrectlist    *rects;
  1500. {
  1501.   double        scaleMarkerInterval;
  1502.   int            canvasWidth;
  1503.   float                time, timeInterval;
  1504.   extern    GC    gcScale;
  1505.   double                x;
  1506.   extern      int       ScaleAxisHeight;
  1507.   extern      int       ScaleTimeHeight;
  1508.   int                   width;
  1509.   int                   i;
  1510.   
  1511.   XClearWindow(display, xid);
  1512.   
  1513.   canvasWidth = irint(Zoom *WaveWindowWidth);
  1514.   if (canvasWidth < WaveWindowWidth)
  1515.     canvasWidth = WaveWindowWidth;
  1516.   ScaleCanvasPenColor("black");
  1517.   timeInterval = 1.0;
  1518.   
  1519.   scaleMarkerInterval = WaveWindowWidth / 10.0 * Zoom;
  1520.   
  1521.   for(i = 1 ; scaleMarkerInterval > 200.0; )
  1522.   {
  1523.     if (i == 1)
  1524.     {
  1525.       timeInterval /= 2.0;
  1526.       scaleMarkerInterval /= 2.0;
  1527.       i = 5;
  1528.     }
  1529.     else
  1530.     {
  1531.       timeInterval /= 5.0;
  1532.       scaleMarkerInterval /= 5.0;
  1533.       i = 1;
  1534.     }
  1535.   }
  1536.   
  1537.   XDrawLine(display, xid, gcScale, 0, ScaleAxisHeight, 
  1538.         canvasWidth, ScaleAxisHeight);
  1539.   
  1540.   x = 0.0;
  1541.   XDrawLine(display, xid, gcScale, 
  1542.         irint(x), ScaleAxisHeight+5, irint(x), ScaleAxisHeight-5);
  1543.   
  1544.   for(x = scaleMarkerInterval, time = FrameStartingSecond + timeInterval; 
  1545.       x < (double) canvasWidth ; 
  1546.       x += scaleMarkerInterval, time += timeInterval)
  1547.   {
  1548.     ScaleCanvasPenColor("black");    
  1549.     XDrawLine(display, xid, gcScale, 
  1550.           irint(x), ScaleAxisHeight+5, irint(x), ScaleAxisHeight-5);
  1551.     sprintf(msg, "%.2f s", time);
  1552.     width = strlen(msg) * 5.0;
  1553.     ScaleCanvasPenColor("black");
  1554.     XDrawString(display, xid, gcScale, 
  1555.         irint(x-(width/2.0)), ScaleTimeHeight, msg, strlen(msg));
  1556.   }
  1557.   
  1558. }
  1559.  
  1560.  
  1561. /*
  1562.  * Notify callback function for `RecordButton'.
  1563.  */
  1564. void
  1565.   RecordButtonHandler(item, event)
  1566. Panel_item    item;
  1567. Event        *event;
  1568. {
  1569.   dtr_mainWindow_objects    *ip = 
  1570.     (dtr_mainWindow_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  1571.   
  1572.   if ((ActiveFlag & PLAY) || (WaitFlag & PLAY))                /*  Record stops in-progress Play.                  */
  1573.     StopPlay();
  1574.   
  1575.   if (WaitFlag & RECORD)
  1576.   {
  1577.     StopRecord();                            /*  Never got the device.                           */
  1578.     return;
  1579.   }
  1580.   else if (ActiveFlag & RECORD)
  1581.   {                                    /*  Stop button pressed.                            */
  1582.     StopRecord();
  1583.     if (Audio_state.record.error)
  1584.     {
  1585.       AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  1586.               "Overflow detected during Record.");
  1587.     }
  1588.     return;
  1589.   }
  1590.   
  1591.   switch (AudioOpen(RECORD))
  1592.   {
  1593.    case 0:                                /*  Open succeeded.                                 */
  1594.     break;
  1595.     
  1596.    case 1:                                /*  Open returned EBUSY.                            */
  1597.     AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  1598.             "Audio device currently in use.");
  1599.     return;
  1600.     
  1601.    case -1:                                /*  Open error.                                     */
  1602.    default:
  1603.     AlertByNoticePrompt(dtr_mainWindow->menuControlPanel,
  1604.             "Error opening audio device.");
  1605.     return;
  1606.   }
  1607.   
  1608.   strcpy(Buffer.filename,"\0");                        /*  Clear buffer filename to avoid filename...      */
  1609.   sprintf(currentSoundFile,"Untitled");                    /*  ...conflict.                                    */
  1610.   UpdateHeader(FALSE);
  1611.   ClearMessageDisplay();
  1612.   ClearWaveCanvas();
  1613.   ClearGlobalWaveCanvas();
  1614.   StartRecord();
  1615. }                                    /* end function RecordButtonHandler */
  1616.  
  1617.  
  1618. /*
  1619.  * Notify callback function for `PlayGain'.
  1620.  */
  1621. void
  1622.   PlayGainSlider(item, value, event)
  1623. Panel_item    item;
  1624. int        value;
  1625. Event        *event;
  1626. {
  1627.   double  gain;
  1628.   
  1629.   gain = ScaleGain(value);
  1630.   Audio_state.play.gain = ~0;
  1631.   (void) audio_set_play_gain(Audioctl_fd, &gain);
  1632.   if (item == dtr_mainWindow->playGain)                    /* Make sure the other volume level slider shows the same... */
  1633.     xv_set(dtr_editListPanelPopUp->editListVolumeSlider,        /* ...value as this one does */
  1634.        PANEL_VALUE, value, NULL);
  1635.   else
  1636.     xv_set(dtr_mainWindow->playGain,
  1637.        PANEL_VALUE, value, NULL);
  1638.   return;
  1639. }
  1640.  
  1641.  
  1642. /*
  1643.  * Notify callback function for `RecordGain'.
  1644.  */
  1645. void
  1646.   RecordGainSlider(item, value, event)
  1647. Panel_item    item;
  1648. int        value;
  1649. Event        *event;
  1650. {
  1651.   double gain;
  1652.   
  1653.   gain = ScaleGain(value);                        /*  Let SIGPOLL handler adjust displayed value.     */
  1654.   Audio_state.record.gain = ~0;
  1655.   (void) audio_set_record_gain(Audioctl_fd, &gain);
  1656. }
  1657.  
  1658.  
  1659. /*
  1660.  * Repaint callback function for `VUMeterCanvas'.
  1661.  */
  1662. void
  1663.   VUMeterCanvasRepaintHandler(canvas, paint_window, rects)
  1664. Canvas        canvas;
  1665. Xv_window    paint_window;
  1666. Rectlist    *rects;
  1667. {
  1668.   ClearVUMeterCanvas();
  1669. }
  1670.  
  1671.  
  1672. /*
  1673.  * Notify callback function for `ZoomSlider'.
  1674.  */
  1675. void
  1676.   ZoomSliderHandler(item, value, event)
  1677. Panel_item    item;
  1678. int        value;
  1679. Event        *event;
  1680. {
  1681.   extern Xv_Window paintWinWave;
  1682.   extern Display   *dpyWave;
  1683.   extern Window    xid;
  1684.   extern int       ScrollbarPixelsPerUnit;
  1685.   
  1686.   if (strcmp(currentSoundFile, "Untitled") != 0)
  1687.   {
  1688.     return;
  1689.   }
  1690.   xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);        /*  Reset scrollbar first, this fixes the weird.... */
  1691.                                     /*  ...canvas bug.                                  */
  1692.   Zoom = value/100.0;
  1693.   sprintf(msg, "%.2lf", Zoom);                        /*  Update the zoom-level text field.               */
  1694.   xv_set(dtr_mainWindow->zoomLevelTextField, 
  1695.      PANEL_VALUE, msg, NULL);
  1696.   FrameStartingSecond = (irint(oldLeftFloatMarker /
  1697.                    DefaultWaveCanvasDataSamplingInterval) /
  1698.              (WaveWindowWidth / 2)) * 5.0;
  1699.   RepaintWaveCanvas();
  1700.   CenterWaveCanvasHighlightedSegment();
  1701.   UpdateCanvasFrame();
  1702. }
  1703.  
  1704.  
  1705. /*
  1706.  * Event callback function for `ZoomLevelTextField'.
  1707.  */
  1708. Panel_setting
  1709.   ZoomLevelTextFieldHandler(item, event)
  1710. Panel_item    item;
  1711. Event        *event;
  1712. {
  1713.   char     *value = (char *) xv_get(item, PANEL_VALUE);
  1714.   double   newZoom;
  1715.   
  1716.   if (strcmp(currentSoundFile, "Untitled") ==0)
  1717.   {
  1718.     ClearWaveCanvas();
  1719.     return panel_text_notify(item, event);
  1720.   }  
  1721.   newZoom = atof(value);
  1722.   if (newZoom <= 1.0 || newZoom > (double) MAX_ZOOM)
  1723.   {
  1724.     AlertByNoticePrompt(dtr_mainWindow->mainWindow,
  1725.             "Error:  Illegal zoom value.");
  1726.   }
  1727.   else
  1728.   {
  1729.     xv_set(WaveCanvasScrollbar, SCROLLBAR_VIEW_START, 0, NULL);        /*  Reset scrollbar first, this fixes the weird.... */
  1730.                                     /*  ...canvas bug.                                  */
  1731.     Zoom = newZoom;
  1732.     UpdateZoomLevelDisplay();
  1733.     RepaintWaveCanvas();
  1734.     CenterWaveCanvasHighlightedSegment();
  1735.     UpdateCanvasFrame();
  1736.   }
  1737.   return panel_text_notify(item, event);
  1738. }
  1739.  
  1740.  
  1741. /*
  1742.  * Event callback function for `globalWaveCanvasPopUp'.
  1743.  */
  1744. Notify_value
  1745.   GlobalWaveCanvasEventHandler(win, event, arg, type)
  1746. Xv_window    win;
  1747. Event        *event;
  1748. Notify_arg    arg;
  1749. Notify_event_type type;
  1750. {
  1751.   extern       int     GbWaveLeftButtonHoldPoint;
  1752.   static     int     sawLeftDown = 0;
  1753.   static     int     sawMiddleDown = 0;
  1754.   static     int    lastWinX;
  1755.   int                   WaveCanvasWinX;
  1756.   extern        BOOL    AboutToCopy;
  1757.   extern    BOOL    AboutToPaste;
  1758.   extern    BOOL    CutPortionReady;
  1759.   
  1760.   if (ActiveFlag)                            /*  If playing or recording, return without doing.. */
  1761.     return notify_next_event_func(win, (Notify_event) event,        /*  ...anything.                                    */
  1762.                   arg, type);
  1763.   
  1764.   if (AboutToCopy)                            /*  Check if the mouse click is meant to be a...    */
  1765.   {                                    /*  ...copy-click.                                  */
  1766.     if (WaveCanvasRightMarkerSet && (event_id(event) == MS_RIGHT ||
  1767.                      event_id(event) == MS_MIDDLE ||
  1768.                      event_id(event) == MS_LEFT)) 
  1769.       WaveCopyHandler(irint(event_x(event) * 
  1770.                 GlobalWaveCanvasDataSamplingInterval));
  1771.     return notify_next_event_func(win, (Notify_event) event, 
  1772.                   arg, type);
  1773.   }
  1774.   if (AboutToPaste)                            /*  Check if the mouse click is meant to be a...    */
  1775.   {                                    /*  ...paste-click.                                 */
  1776.     if (CutPortionReady && (event_id(event) == MS_RIGHT ||
  1777.                 event_id(event) == MS_MIDDLE ||
  1778.                 event_id(event) == MS_LEFT)) 
  1779.       WavePasteHandler(irint(event_x(event) * 
  1780.                  GlobalWaveCanvasDataSamplingInterval));
  1781.     return notify_next_event_func(win, (Notify_event) event, 
  1782.                   arg, type);
  1783.   }
  1784.   WaveCanvasWinX = irint(event_x(event) *                /*  Calculate the other wave canvas's window x...   */
  1785.              GlobalWaveCanvasDataSamplingInterval /        /*  ...value.                                       */
  1786.              WaveCanvasDataSamplingInterval);
  1787.   
  1788.   if (event_id(event) == MS_LEFT)
  1789.   {
  1790.     if (event_is_down(event))
  1791.     {
  1792.       sawLeftDown = 1;
  1793.       GbWaveLeftButtonHoldPoint = event_x(event);
  1794.       leftButtonHoldPoint = WaveCanvasWinX;
  1795.       WaveCanvasMarkerHandler(WaveCanvasWinX, &oldLeftFloatMarker);
  1796.       WaveCanvasMarkerHandler(WaveCanvasWinX, &oldRightFloatMarker);
  1797.       GlobalWaveCanvasMarkerHandler(event_x(event),
  1798.                     &oldLeftFloatGbWaveMarker);
  1799.       GlobalWaveCanvasMarkerHandler(event_x(event),
  1800.                     &oldRightFloatGbWaveMarker);
  1801.     }
  1802.     else if (event_is_up(event))
  1803.     {
  1804.       sawLeftDown = 0;
  1805.     }
  1806.   }
  1807.   else if (event_id(event) == MS_MIDDLE)
  1808.   {
  1809.     if (event_is_down(event))
  1810.     {
  1811.       sawMiddleDown = 1;
  1812.       if (GbWaveLeftButtonHoldPoint == NOTREADY)
  1813.       {
  1814.     GbWaveLeftButtonHoldPoint = event_x(event);
  1815.     leftButtonHoldPoint = WaveCanvasWinX;
  1816.     WaveCanvasMarkerHandler(WaveCanvasWinX, &oldLeftFloatMarker);
  1817.     WaveCanvasMarkerHandler(WaveCanvasWinX, &oldRightFloatMarker);
  1818.     GlobalWaveCanvasMarkerHandler(event_x(event),
  1819.                       &oldLeftFloatGbWaveMarker);
  1820.     GlobalWaveCanvasMarkerHandler(event_x(event),
  1821.                       &oldRightFloatGbWaveMarker);
  1822.       } 
  1823.       else
  1824.       {
  1825.     if (event_x(event) < GbWaveLeftButtonHoldPoint) {
  1826.       /********
  1827.         if (lastWinX > GbWaveLeftButtonHoldPoint) {
  1828.         WaveCanvasMarkerHandler(leftButtonHoldPoint,
  1829.         &oldRightFloatMarker);
  1830.         GlobalWaveCanvasMarkerHandler(GbWaveLeftButtonHoldPoint,
  1831.         &oldRightFloatGbWaveMarker);
  1832.         }
  1833.         ********/
  1834.       WaveCanvasBackwardMarkerHandler(WaveCanvasWinX, 
  1835.                       &oldLeftFloatMarker);
  1836.       
  1837.       GlobalWaveCanvasBackwardMarkerHandler(event_x(event),
  1838.                         &oldLeftFloatGbWaveMarker);
  1839.     }
  1840.     else
  1841.     {
  1842.       if (lastWinX < GbWaveLeftButtonHoldPoint)
  1843.       {
  1844.         WaveCanvasBackwardMarkerHandler(
  1845.                         leftButtonHoldPoint, 
  1846.                         &oldLeftFloatMarker);
  1847.         GlobalWaveCanvasBackwardMarkerHandler(
  1848.                           GbWaveLeftButtonHoldPoint, 
  1849.                           &oldLeftFloatGbWaveMarker);
  1850.       }
  1851.       WaveCanvasMarkerHandler(WaveCanvasWinX, 
  1852.                   &oldRightFloatMarker);
  1853.       GlobalWaveCanvasMarkerHandler(event_x(event),
  1854.                     &oldRightFloatGbWaveMarker);
  1855.     }    
  1856.       }
  1857.       
  1858.     }
  1859.     else if (event_is_up(event))
  1860.     {
  1861.       sawMiddleDown = 0;
  1862.     }
  1863.   } 
  1864.   else if (event_id(event) == LOC_DRAG && (sawLeftDown || sawMiddleDown))
  1865.   {
  1866.     if (event_x(event) < GbWaveLeftButtonHoldPoint)
  1867.     {
  1868.       if (lastWinX > GbWaveLeftButtonHoldPoint)
  1869.       {
  1870.     WaveCanvasMarkerHandler(leftButtonHoldPoint, 
  1871.                 &oldRightFloatMarker);
  1872.     GlobalWaveCanvasMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1873.                       &oldRightFloatGbWaveMarker);
  1874.       }
  1875.       WaveCanvasBackwardMarkerHandler(WaveCanvasWinX, 
  1876.                       &oldLeftFloatMarker);
  1877.       GlobalWaveCanvasBackwardMarkerHandler(event_x(event),
  1878.                         &oldLeftFloatGbWaveMarker);
  1879.     }
  1880.     else
  1881.     {
  1882.       if (lastWinX < GbWaveLeftButtonHoldPoint)
  1883.       {
  1884.     WaveCanvasBackwardMarkerHandler(leftButtonHoldPoint, 
  1885.                     &oldLeftFloatMarker);
  1886.     GlobalWaveCanvasBackwardMarkerHandler(GbWaveLeftButtonHoldPoint, 
  1887.                           &oldLeftFloatGbWaveMarker);
  1888.       }
  1889.       WaveCanvasMarkerHandler(WaveCanvasWinX, &oldRightFloatMarker);
  1890.       GlobalWaveCanvasMarkerHandler(event_x(event),
  1891.                     &oldRightFloatGbWaveMarker);
  1892.     }
  1893.   } 
  1894.   
  1895.   lastWinX = event_x(event);
  1896.   UpdateSelection();
  1897.   return notify_next_event_func(win, (Notify_event) event, arg, type);
  1898. }                                    /* end function GlobalWaveCanvasEventHandler */
  1899.  
  1900. /*
  1901.  * Repaint callback function for `GlobalWaveCanvas'.
  1902.  */
  1903. void
  1904.   GlobalWaveCanvasRepaintHandler(canvas, paint_window, display, xid, rects)
  1905. Canvas        canvas;
  1906. Xv_window    paint_window;
  1907. Display        *display;
  1908. Window        xid;
  1909. Rectlist    *rects;
  1910. {
  1911.   int          pt;
  1912.   int          dataEnd;
  1913.   int          i;
  1914.   int          from, to;
  1915.   extern   GC     gcGbWave;
  1916.   int          heightOffset;
  1917.   double       floatpt;
  1918.   int          leftWinX, rightWinX;
  1919.   unsigned char data;
  1920.   
  1921.     
  1922.   XClearWindow(display, xid);
  1923.   
  1924.   GlobalWaveCanvasDataSamplingInterval = ((double)Buffer.hdr.data_size)/
  1925.     (double)GlobalWaveWindowWidth;
  1926.   
  1927.   heightOffset = GlobalWaveCanvasMidHeight;
  1928.   GlobalWaveCanvasPenColor("White");
  1929.   to = heightOffset;
  1930.   floatpt = 0.0;
  1931.   dataEnd = irint((double)Buffer.hdr.data_size - 
  1932.           GlobalWaveCanvasDataSamplingInterval);
  1933.   
  1934.   if (FileReady)
  1935.   {
  1936.     soundfd = open(Buffer.filename, O_RDONLY);
  1937.     lseek(soundfd, Buffer.hdr_size, L_SET);
  1938.     
  1939.     for(i=0, pt=0; pt < dataEnd ; i++)
  1940.     {
  1941.       from = to;
  1942.       read(soundfd, &data, 1);
  1943.       to   = ((audio_u2c(data) * GlobalWaveScopeWidth) >> 7)
  1944.     + heightOffset;
  1945.       XDrawLine(display, xid, gcGbWave, i-1, from, i, to);
  1946.       floatpt += GlobalWaveCanvasDataSamplingInterval;
  1947.       lseek(soundfd, irint(floatpt) - pt, L_INCR);
  1948.       pt = irint(floatpt);
  1949.     }
  1950.     close(soundfd);
  1951.   }
  1952.   else if (SoundBufferReady == TRUE)
  1953.   {
  1954.     for(i=0, pt=0 ; pt < dataEnd ; i++)
  1955.     {
  1956.       from = to;
  1957.       to   = ((audio_u2c(Buffer.data[pt]) * GlobalWaveScopeWidth) >> 7)
  1958.     + heightOffset;
  1959.     
  1960.       XDrawLine(display, xid, gcGbWave, i-1, from, i, to);
  1961.     
  1962.       floatpt = floatpt + GlobalWaveCanvasDataSamplingInterval;
  1963.       pt = irint(floatpt);
  1964.     }
  1965.   }
  1966.   
  1967.   XDrawLine(display, xid, gcGbWave, 0, GlobalWaveCanvasMidHeight,
  1968.         GlobalWaveCanvasWidth-1, GlobalWaveCanvasMidHeight);
  1969.   
  1970.   if (GlobalWaveCanvasRightMarkerSet)                    /*  HighLight marked area.                          */
  1971.   {
  1972.     rightWinX = irint(oldRightFloatGbWaveMarker/
  1973.               GlobalWaveCanvasDataSamplingInterval);
  1974.     leftWinX  = irint(oldLeftFloatGbWaveMarker/
  1975.               GlobalWaveCanvasDataSamplingInterval);
  1976.     ReverseGlobalWaveCanvasArea(leftWinX, rightWinX);
  1977.   }
  1978.   DisplayCanvasFrame();
  1979. }                                    /* end function GlobalWaveCanvasRepaintHandler */
  1980.  
  1981.  
  1982. /*
  1983.  * Event callback function for `GlobalWaveCanvasDoneButton'.
  1984.  */
  1985. void
  1986.   GlobalWaveCanvasDoneHandler(item, event)
  1987. Panel_item    item;
  1988. Event        *event;
  1989. {
  1990.   xv_set(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, 
  1991.      FRAME_CMD_PUSHPIN_IN, FALSE, NULL);
  1992.   xv_set(dtr_globalWaveCanvasPopUp->globalWaveCanvasPopUp, 
  1993.      XV_SHOW, FALSE, NULL);
  1994.   panel_default_handle_event(item, event);
  1995. }
  1996.  
  1997.  
  1998. /*
  1999.  * Notify callback function for `EditListScrollList'.
  2000.  */
  2001. int
  2002. DumpEntry(item, string, client_data, op, event)
  2003.      Panel_item    item;
  2004.      char        *string;
  2005.      Xv_opaque    client_data;
  2006.      Panel_list_op    op;
  2007.      Event        *event;
  2008. {
  2009.   switch(op)
  2010.   {
  2011.    case PANEL_LIST_OP_DESELECT:
  2012.     DeselectList();
  2013.     break;
  2014.     
  2015.    case PANEL_LIST_OP_SELECT:
  2016.     if (ActiveFlag & PLAY)
  2017.       StopPlay();
  2018.     if (ActiveFlag & RECORD)
  2019.       StopRecord();
  2020.     
  2021.     currentSelection = atoi(string) - 1;
  2022.     SetCurrentSelection(currentSelection, (MAESelection*)NULL);
  2023.     xv_set(dtr_editListPanelPopUp->deleteButton,
  2024.        PANEL_INACTIVE, FALSE, NULL);                /*  De-activate the Delete and Modify buttons.      */
  2025.     xv_set(dtr_editListPanelPopUp->modifyButton,
  2026.        PANEL_INACTIVE, FALSE, NULL);
  2027.     xv_set(dtr_editListPanelPopUp->deleteAllButton,
  2028.        PANEL_INACTIVE, FALSE, NULL);
  2029.     break;
  2030.     
  2031.    case PANEL_LIST_OP_VALIDATE:
  2032.    case PANEL_LIST_OP_DELETE:
  2033.     break;
  2034.   }
  2035.   return XV_OK;
  2036. }                                    /* end function DumpEntry */
  2037.  
  2038.  
  2039. /*
  2040.  * Notify callback function for `LabelTextField'.
  2041.  */
  2042. Panel_setting
  2043. LabelTextFieldHandler(item, event)
  2044.     Panel_item    item;
  2045.     Event        *event;
  2046. {
  2047.   return panel_text_notify(item, event);
  2048. }
  2049.  
  2050.  
  2051.  
  2052. void UpdateSelection()
  2053. {
  2054.   double    startingTimeInSec;
  2055.   double    endingTimeInSec;
  2056.   int        min;
  2057.   double    sec;
  2058.   char        proposedPath[MAXPATHLEN];
  2059.   
  2060.   if ((strcmp(currentSoundFile, "Untitled") != 0) || currentSoundFile == NULL)
  2061.   {
  2062.     realpath(currentSoundFile, proposedPath);
  2063.     xv_set(dtr_editListPanelPopUp->soundFileTextField,
  2064.        PANEL_VALUE, proposedPath,
  2065.        NULL);
  2066.   }
  2067.   else
  2068.   {
  2069.     xv_set(dtr_editListPanelPopUp->soundFileTextField,
  2070.        PANEL_VALUE, "", NULL);
  2071.   }
  2072.   startingTimeInSec = Buffer.play.start / (double) DEVICE_SAMPLE_RATE;
  2073.   min = irint(floor(startingTimeInSec / 60.0));
  2074.   sec = startingTimeInSec - (60.0 * min);
  2075.   sprintf(msg, "%d", min);
  2076.   xv_set(dtr_editListPanelPopUp->startingTimeMinuteTextField,
  2077.      PANEL_VALUE, msg, NULL);
  2078.   sprintf(msg, "%.2lf", sec);
  2079.   xv_set(dtr_editListPanelPopUp->startingTimeSecondTextField,
  2080.      PANEL_VALUE, msg, NULL);
  2081.   endingTimeInSec   = Buffer.play.end   / (double) DEVICE_SAMPLE_RATE;
  2082.   min = irint(floor(endingTimeInSec / 60.0));
  2083.   sec = endingTimeInSec - (60.0 * min);
  2084.   sprintf(msg, "%d", min);
  2085.   xv_set(dtr_editListPanelPopUp->endingTimeMinuteTextField,
  2086.      PANEL_VALUE, msg, NULL);
  2087.   sprintf(msg, "%.4lf", sec);
  2088.   xv_set(dtr_editListPanelPopUp->endingTimeSecondTextField,
  2089.      PANEL_VALUE, msg, NULL);
  2090. }                                    /* end function UpdateSelection */
  2091.  
  2092.  
  2093.  
  2094. /*
  2095.  * Notify callback function for `SetEditSelectionButton'.
  2096.  */
  2097. void
  2098. SetEditSelectionButtonHandler(item, event)
  2099.     Panel_item    item;
  2100.     Event        *event;
  2101. {
  2102.   if (ActiveFlag & PLAY)
  2103.     StopPlay();
  2104.   if (ActiveFlag & RECORD)
  2105.     StopRecord();
  2106.   SetCurrentSelection(currentSelection, (MAESelection*)NULL);
  2107. }
  2108.  
  2109.  
  2110. /*
  2111.  * Notify callback function for `AddButton'.
  2112.  */
  2113. void
  2114. AddButtonHandler(item, event)
  2115.     Panel_item    item;
  2116.     Event        *event;
  2117. {
  2118.   AddSelection();
  2119. }
  2120.  
  2121.  
  2122.  
  2123. /*
  2124.  * Notify callback function for `ModifyButton'.
  2125.  */
  2126. void
  2127. ModifyButtonHandler(item, event)
  2128.     Panel_item    item;
  2129.     Event        *event;
  2130. {
  2131.   ModifySelection();
  2132. }
  2133.  
  2134.  
  2135. /*
  2136.  * Notify callback function for `DeleteButton'.
  2137.  */
  2138. void
  2139. DeleteButtonHandler(item, event)
  2140.     Panel_item    item;
  2141.     Event        *event;
  2142. {
  2143.   DeleteSelection();
  2144. }
  2145.  
  2146.  
  2147. /*
  2148.  * Notify callback function for `DeleteAllButton'.
  2149.  */
  2150. void
  2151. DeleteAllButtonHandler(item, event)
  2152.     Panel_item    item;
  2153.     Event        *event;
  2154. {
  2155.   DeleteAllSelections();
  2156. }
  2157.  
  2158.  
  2159. /*
  2160.  * Notify callback function for `PreviewEditButton'.
  2161.  */
  2162. void
  2163. PreviewEditButtonHandler(item, event)
  2164.     Panel_item    item;
  2165.     Event        *event;
  2166. {
  2167.   if (ActiveFlag & PLAY)
  2168.     return;
  2169.   if (ActiveFlag & RECORD)
  2170.     return;
  2171.   if (WaitFlag & PLAY)
  2172.   {
  2173.     AlertByNoticePrompt(dtr_editListPanelPopUp->editListUpperControlPanel,
  2174.             "Device is not ready.  Play Stopped");
  2175.     StopPlay();
  2176.     return;
  2177.   }
  2178.   if (!currentSelectionReadyToPlay)
  2179.     SetCurrentSelection(currentSelection, (MAESelection*)NULL);
  2180.   if ((FileReady == TRUE) || (SoundBufferReady == TRUE))
  2181.   {
  2182.     Play(dtr_mainWindow);
  2183.     SameSoundFile = TRUE;
  2184.   }
  2185. }                                    /* end function PreviewEditButtonHandler */
  2186.